package com.dqx.haoqiu.repository.db;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.dqx.haoqiu.repository.entity.NewsEntity;

import java.util.List;

import io.reactivex.Observable;

/**
 * 数据表操作者
 */
@Dao
public interface NewsDao {

    //查询所有数据
    @Query("Select * from news")
    Observable<List<NewsEntity>> getAll();

    //删除全部数据
    @Query("DELETE FROM news")
    void deleteAll();

    //一次插入单条数据或多条
    @Insert
    void insert(NewsEntity... persons);

    //一次删除单条数据 或 多条
    @Delete
    void delete(NewsEntity... persons);

    //一次更新单条数据 或 多条
    @Update
    void update(NewsEntity... persons);

    //根据字段去查找数据
    @Query("SELECT * FROM news WHERE id= :id")
    Observable<NewsEntity> getNewsById(int id);

    //一次查找多个数据
    @Query("SELECT * FROM news WHERE id IN (:ids)")
    Observable<List<NewsEntity>> loadAllByIds(List<Integer> ids);

    //多个条件查找
    @Query("SELECT * FROM news WHERE title = :title AND id = :id")
    Observable<NewsEntity> getNewsByNameage(String title, int id);

}
